package com.sk.bilibili.model.fragment.main.home.home;

import com.sk.api.annotations.Autowired;
import com.sk.bilibili.R;
import com.sk.bilibili.bean.Live;
import com.sk.bilibili.bean.LiveType;
import com.sk.bilibili.dto.Extra;
import com.sk.bilibili.mapper.HistoryMapper;
import com.sk.bilibili.mapper.LiveBannerMapper;
import com.sk.bilibili.mapper.LiveMapper;
import com.sk.bilibili.mapper.LiveTypeMapper;
import com.sk.bilibili.model.BaseRefreshModel;
import com.sk.bilibili.other.JsonMap;
import com.sk.bilibili.utils.RequestUtils;
import com.sk.bilibili.view.fragment.main.home.home.LiveFragment;

import java.util.ArrayList;
import java.util.List;

public class LiveModel extends BaseRefreshModel<LiveFragment> {

    @Autowired
    LiveBannerMapper liveBannerMapper;
    @Autowired
    LiveMapper liveMapper;
    @Autowired
    LiveTypeMapper liveTypeMapper;
    private List<Extra> list;

    public LiveModel() {
        list=new ArrayList<>();
        list.add(new Extra(R.drawable.live_fullscreen,"全屏直播"));
        list.add(new Extra(R.drawable.live_lol,"英雄联盟"));
        list.add(new Extra(R.drawable.live_hore,"王者荣耀"));
        list.add(new Extra(R.drawable.live_entertainment,"娱乐"));
        list.add(new Extra(R.drawable.live_game,"单机游戏"));
        list.add(new Extra(R.drawable.live_radio,"电台"));
        list.add(new Extra(R.drawable.live_vir,"虚拟主播"));
        list.add(new Extra(R.drawable.live_phone_lol,"LOL手游"));
        list.add(new Extra(R.drawable.live_sing,"视频唱见"));
        list.add(new Extra(R.drawable.live_all,"全部标签"));
    }

    @Override
    public void refreshData() {
        RequestUtils.process(liveBannerMapper.getLiveBanner(0), liveBanners ->
                view.loadLiveBannerSuccess(liveBanners));
        RequestUtils.process(liveMapper.getRecommend(1, 6), lives ->
                view.loadRecommendSuccess(lives));
        view.loadTypeSuccess(list);
    }

    public void loadType() {
        RequestUtils.process(liveTypeMapper.getAll(), liveTypes -> view.loadLiveTypeSuccess(liveTypes));
    }

    public void loadTypeLive(List<LiveType> liveTypes) {
        for (int i = 0; i < liveTypes.size(); i++) {
            int finalI = i;
            RequestUtils.process(liveMapper.getTypeLive(liveTypes.get(i).getId()), lives ->
                    view.loadTypeLiveSuccess(finalI,lives));
        }
    }

}